package com.zjdiepu.www.manage.view;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.dz.IDzPickCarService;
import com.zjdiepu.www.ibiz.fk.IFkTmpCarRecheckService;
import com.zjdiepu.www.ibiz.yw.IYwTransferService;
import com.zjdiepu.www.model.dz.dto.DzPickCar;
import com.zjdiepu.www.model.dz.ext.DzPickCarExt;
import com.zjdiepu.www.model.fk.dto.FkTmpCarRecheck;
import com.zjdiepu.www.model.fk.ext.FkTmpCarRecheckExt;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwTransfer;
import com.zjdiepu.www.model.yw.ext.YwTransferExt;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;
import com.zjdiepu.www.util.ExceptionHelper;

/**
 * 车辆资料复审Controller层<br/>
 * @author xiongxiaotun<br/>
 * @time 2017年05月09日 19时30分<br/>
 * @since 1.0<br/>
 */
@Controller
@RequestMapping(value= "FkTmpCarRecheckViewController", produces="text/html;charset=UTF-8")
@Api(tags = {"车辆资料复审"}, produces="text/html;charset=UTF-8")
public class FkTmpCarRecheckViewController extends BaseController {
	@Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
    @Resource
    private ICachedDictionaryService cachedDictionaryService;
//    @Resource
//    private IDzRegistrationService dzRegistrationService;
    @Resource
    private IDzPickCarService dzPickCarService;
    @Resource
    private IYwTransferService ywTransferService;
    @Resource
    private IFkTmpCarRecheckService fkTmpCarRecheckService;
	
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: vehicleDataReviewDetail  <br/>
     * @Description: 车辆资料复审详情 <br/>
     * @param model
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "车辆资料复审详情", response = Boolean.class, httpMethod="GET", tags={"车辆资料复审"})
    @RequestMapping(value = "vehicleDataReviewDetail", method = RequestMethod.GET)
    public String liftConfirmationDetail(Model model, String id) {
    	if (StringUtils.isBlank(id)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	//业务信息
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(id, model);
    	//车辆资料
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(id,ywBusinessDetail.getCustomerId(), model);
    	//车贷资料
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(id, car.getId(), model, car.getCarType());
    	}
    	//历史业务
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	//车型选择
    	viewScopeControllerHelper.preparedCarModel(model);
    	
    	//车牌登记
//    	DzRegistrationExt dzRegistrationExt = new DzRegistrationExt();
//    	dzRegistrationExt.setBaseWhere();
//    	dzRegistrationExt.setBusiId(id);
//    	dzRegistrationExt.setRows(1);
//    	List<DzRegistration> dzRegistrations = dzRegistrationService.selectByExt(dzRegistrationExt);
//    	if(CollectionUtils.isNotEmpty(dzRegistrations)) {
//    		DzRegistration dzRegistration = dzRegistrations.get(0);
//    		model.addAttribute("dzRegistration", dzRegistration);
//    		//车牌注册地
//    		viewScopeControllerHelper.preparedRegin(model, dzRegistration.getProvinceRegistration(), dzRegistration.getAreaRegistration());
//    	} else {
//    		viewScopeControllerHelper.preparedRegin(model,null,null);
//    	}
    	//新车提车
    	DzPickCarExt dzPickCarExt = new DzPickCarExt();
    	dzPickCarExt.setRows(1);
    	dzPickCarExt.setBusiId(id);
    	dzPickCarExt.setBaseWhere();
    	List<DzPickCar> dzPickCars = dzPickCarService.selectByExt(dzPickCarExt);
    	if(CollectionUtils.isNotEmpty(dzPickCars)) {
    		DzPickCar dzPickCar = dzPickCars.get(0);
    		model.addAttribute("dzPickCar", dzPickCar);
    	}
    	//二手车过户
    	YwTransferExt ywTransferExt = new YwTransferExt();
    	ywTransferExt.setRows(1);
    	ywTransferExt.setBusiId(id);
    	ywTransferExt.setBaseWhere();
    	List<YwTransfer> ywTransfers = ywTransferService.selectByExt(ywTransferExt);
    	if(CollectionUtils.isNotEmpty(ywTransfers)) {
    		YwTransfer ywTransfer = ywTransfers.get(0);
    		model.addAttribute("ywTransfer", ywTransfer);
    	}
    	//保存临时车辆资料
    	FkTmpCarRecheckExt fkTmpCarRecheckExt = new FkTmpCarRecheckExt();
    	fkTmpCarRecheckExt.setRows(1);
    	fkTmpCarRecheckExt.setBusiId(id);
    	fkTmpCarRecheckExt.setBaseWhere();
    	List<FkTmpCarRecheck> fkTmpCarRechecks = fkTmpCarRecheckService.selectByExt(fkTmpCarRecheckExt);
    	if(CollectionUtils.isNotEmpty(fkTmpCarRechecks)) {
    		FkTmpCarRecheck fkTmpCarRecheck = fkTmpCarRechecks.get(0);
    		model.addAttribute("fkTmpCarRecheck", fkTmpCarRecheck);
    	}
    	return "system/loaning/vehicleDataReviewDetail";
    }

}
